﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GUILibrary;
using Microsoft.Xna.Framework.Graphics;
using MapLibrary.Players.Skills;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace MapLibrary.GUI
{
    class ProteinBarButton : Button
    {
        public const int BAR_HEIGHT = 20;
        public const int BAR_WIDTH = 40;

        private Texture2D barTexture;
        private SkillData skillData;

        private int proteinId;

        public ProteinBarButton(int proteinId, SkillData skillData) : base()
        {
            this.skillData = skillData;
            this.proteinId = proteinId;
        }

        public override int Width
        {
            get { return BAR_WIDTH; }
        }

        public override int Height
        {
            get { return BAR_HEIGHT; }
        }

        public override Rectangle Bounds
        {
            get { return new Rectangle(
                (int)this.Position.X,
                (int)this.Position.Y,
                Width,
                Height); 
            }
        }

        public override void load(ContentManager cm)
        {
            barTexture = cm.Load<Texture2D>(@"whitebox");
        }

        public override void Draw(SpriteBatch batch)
        {
            //this rectangle is the full background for the bar.
            Rectangle fullRect = new Rectangle(
                (int)this.Position.X,
                (int)this.Position.Y,
                BAR_WIDTH,
                BAR_HEIGHT);

            //calculate the percentage for the bar
            float percentFull = skillData.PercentComplete(proteinId);
            Rectangle partRect = new Rectangle(
                (int)this.Position.X,
                (int)this.Position.Y,
                (int)(BAR_WIDTH * percentFull),
                BAR_HEIGHT);

            batch.Draw(barTexture, fullRect, Color.Black);
            batch.Draw(barTexture, partRect, Color.Blue);
        }
    }
}
